import request from '@/utils/request'

// 岗位相关接口
export function getJobsList(params) {
  return request({
    url: '/position/list',
    method: 'get',
    params
  })
}

export function getJobDetail(positionId) {
  return request({
    url: `/position/getPosition`,
    method: 'get',
    params:{positionId}
  })
}

export function createJob(data) {
  return request({
    url: '/position',
    method: 'post',
    data
  })
}

export function updateJob(id, data) {
  return request({
    url: `/position/${id}`,
    method: 'put',
    data
  })
}

export function deleteJob(id) {
  return request({
    url: `/position/${id}`,
    method: 'delete'
  })
}

export function updateJobStatus(id, status) {
  return request({
    url: `/position/${id}/status`,
    method: 'patch',
    data: { status }
  })
}

// 批量删除
export function batchDeleteJobs(jobIds) {
  return request({
    url: '/position/batchDelete',
    method: 'delete',
    data: { jobIds }
  })
}

// 客户申请职位接口
export function submitJobApplication(data) {
  return request({
    url: '/customers/add',
    method: 'post',
    data
  })
}

// 获取分享者信息接口
export function getShareUserInfo(userId) {
  return request({
    url: `/system/user/${userId}`,
    method: 'get'
  })
}

// 生成分享链接接口
export function generateShareLink(jobId, userId) {
  return request({
    url: '/position/share',
    method: 'post',
    data: { jobId, userId }
  })
}

// 学习资料相关接口
export function getMaterialsList(data) {
  return request({
    url: '/materials/list',
    method: 'post',
      data
  })
}

export function getMaterialDetail(id) {
  return request({
    url: `/materials/${id}`,
    method: 'get'
  })
}

export function downloadMaterial(id) {
    const name = id.split('upload')[1]
    return request({
        url: `/common/download`,
        method: 'get',
        responseType: 'blob',
        params:{fileName:name}
    })
}
export function downloadMaterial1(id) {
    return request({
        url: `/materials/${id}/download`,
        method: 'post',
        responseType: 'blob',
        data:{id}
    })
}
export function previewMaterial(id) {
  return request({
    url: `/materials/${id}/preview`,
    method: 'get'
  })
}

// 视频课程相关接口
export function getVideosList(data) {
  return request({
    url: '/videos/list',
    method: 'post',
    data
  })
}

export function getVideoDetail(id) {
  return request({
    url: `/videos/${id}`,
    method: 'get'
  })
}

export function likeVideo(id) {
  return request({
    url: `/videos/${id}/like`,
    method: 'post'
  })
}

export function shareVideo(id) {
  return request({
    url: `/videos/${id}/share`,
    method: 'post'
  })
}

// 考试相关接口
export function getExamsList(data) {
  return request({
    url: '/exams/list',
    method: 'post',
      data
  })
}

export function getExamDetail(id) {
  return request({
    url: `/exams/${id}`,
    method: 'get'
  })
}

// 开始考试
export function startExam(examId, data) {
  return request({
    url: `/exams/${examId}/start`,
    method: 'post',
    data
  })
}

// 提交考试答案
export function submitExam(examId, data) {
  return request({
    url: `/exams/${examId}/submit`,
    method: 'post',
    data
  })
}

// 获取考试结果详情
export function getExamResult(resultId) {
  return request({
    url: `/exams/results/${resultId}`,
    method: 'get'
  })
}
// 获取考试结果详情
export function statsQuestion(data) {
    return request({
        url: `/exams/stats/question`,
        method: 'post',
        data
    })
}
// 获取考试统计
export function statsExams(data) {
    return request({
        url: `/exams/stats`,
        method: 'post',
        data
    })
}

// 获取题目详情
export function getQuestionId(resultId) {
    return request({
        url: `/question/${resultId}`,
        method: 'get'
    })
}

// 获取题目
export function questionList(data) {
    return request({
        url: '/question/list',
        method: 'post',
        data
    })
}
// 获取考试时间
export function examsSchedules(id) {
    return request({
        url: `/exams/schedules/${id}`,
        method: 'get'
    })
}

// 获取用户考试历史
export function getExamHistory(data) {
  return request({
    url: '/exams/history',
    method: 'post',
      data
  })
}

// 获取考试统计
export function getExamStats(params) {
  return request({
    url: '/exams/stats',
    method: 'get',
    params
  })
}

// 获取错题集
export function getWrongQuestions(data) {
  return request({
    url: '/exams/wrong-questions',
    method: 'post',
    data
  })
}

// 保存考试进度（实时保存答题数据）
export function saveExamProgress(data) {
  return request({
    url: '/exams/progress',
    method: 'post',
    data
  })
}

// 获取考试会话状态
export function getExamSessionStatus(sessionId) {
  return request({
    url: `/exams/session/${sessionId}/status`,
    method: 'get'
  })
}

// 恢复考试会话
export function resumeExamSession(sessionId) {
  return request({
    url: `/exams/session/${sessionId}/resume`,
    method: 'post'
  })
}

// 旧的预约考试接口（保留兼容性）
export function bookExam(data) {
  return request({
    url: '/exams/book',
    method: 'post',
    data
  })
}

export function getExamResults(params) {
  return request({
    url: '/exams/results',
    method: 'get',
    params
  })
}

// 用户相关接口
export function getUserInfo() {
  return request({
    url: '/user/info',
    method: 'get'
  })
}

export function updateUserInfo(data) {
  return request({
    url: '/user/info',
    method: 'put',
    data
  })
}

export function changeUserPassword(data) {
  return request({
    url: '/user/password',
    method: 'put',
    data
  })
}

export function getUserStats() {
  return request({
    url: '/user/stats',
    method: 'get'
  })
}

export function getUserPreferences() {
  return request({
    url: '/user/preferences',
    method: 'get'
  })
}

export function updateUserPreferences(data) {
  return request({
    url: '/user/preferences',
    method: 'put',
    data
  })
}

// 学习进度相关接口
export function getLearningProgress(params) {
  return request({
    url: '/learning/progress',
    method: 'get',
    params
  })
}

export function updateLearningProgress(data) {
  return request({
    url: '/learning/progress',
    method: 'put',
    data
  })
}

export function getRecentExams() {
  return request({
    url: '/learning/recent-exams',
    method: 'get'
  })
}

export function getRecentMessages() {
  return request({
    url: '/messages/recent',
    method: 'get'
  })
}

// 消息相关接口
export function getMessagesList(params) {
  return request({
    url: '/messages/list',
    method: 'get',
    params
  })
}

export function getMessageSettings() {
  return request({
    url: '/messages/settings',
    method: 'get'
  })
}

export function updateMessageSettings(data) {
  return request({
    url: '/messages/settings',
    method: 'put',
    data
  })
}

export function markMessageRead(id) {
  return request({
    url: `/messages/${id}/read`,
    method: 'patch'
  })
}

export function batchMarkMessagesRead(ids) {
  return request({
    url: '/messages/batch-read',
    method: 'patch',
    data: { ids }
  })
}

export function snoozeMessage(id) {
  return request({
    url: `/messages/${id}/snooze`,
    method: 'patch'
  })
}

// 文件上传接口
export function uploadFiles(data) {
  return request({
    url: '/upload/files',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export function uploadFile(data) {
  return request({
    url: '/upload/file',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}


export function examstypeList(data) {
    return request({
        url: '/examstype/list',
        method: 'post',
        data
    })
}
export function getExamstypeDetail(id) {
    return request({
        url: `/examstype/${id}`,
        method: 'get'
    })
}
// 查询考试领域列表
export function listExamslevel(data) {
    return request({
        url: '/examslevel/list',
        method: 'post',
        data
    })
}

// 查询图片配置列表
export function listImages(data) {
    return request({
        url: '/www/images/list',
        method: 'post',
        data
    })
}
